package com.gxp.web.controller;

import com.gxp.common.annotation.Audit;
import com.gxp.common.core.controller.BaseController;
import com.gxp.common.core.domain.AjaxResult;
import com.gxp.common.core.domain.entity.ZkServiceType;
import com.gxp.common.core.page.TableDataInfo;
import com.gxp.common.enums.BusinessAction;
import com.gxp.common.enums.BusinessTitle;
import com.gxp.common.utils.DateUtils;
import com.gxp.system.service.IZkServiceTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务类型Controller
 * 
 * @author zh
 * @date 2024-03-07
 */
@Controller
@RequestMapping("/system/svtype")
public class ZkServiceTypeController extends BaseController
{private String prefix = "system/svtype";

    @Autowired
    private IZkServiceTypeService zkServiceTypeService;

    @RequiresPermissions("system:svtype:view")
    @GetMapping()
    public String svtype()
    {
        return prefix + "/svtype";
    }

    /**
     * 查询服务类型列表
     */
    @RequiresPermissions("system:svtype:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZkServiceType zkServiceType)
    {
        startPage();
        List<ZkServiceType> list = zkServiceTypeService.selectZkServiceTypeList(zkServiceType);
        return getDataTable(list);
    }

    /**
     * 新增服务类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存服务类型
     */
    @RequiresPermissions("system:svtype:add")
    @Audit(businessTitle = BusinessTitle.SERVICE_TYPE, businessAction = BusinessAction.CREATED, description = "新增服务类型")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZkServiceType zkServiceType)
    {
        zkServiceType.setCreateBy(getLoginName());
        return toAjax(zkServiceTypeService.insertZkServiceType(zkServiceType));
    }

    /**
     * 修改服务类型
     */
    @RequiresPermissions("system:svtype:edit")
    @GetMapping("/edit/{svtypeId}")
    public String edit(@PathVariable("svtypeId") Long svtypeId, ModelMap mmap)
    {
        ZkServiceType zkServiceType = zkServiceTypeService.selectZkServiceTypeBySvtypeId(svtypeId);
        mmap.put("zkServiceType", zkServiceType);
        return prefix + "/edit";
    }

    /**
     * 修改保存服务类型
     */
    @RequiresPermissions("system:svtype:edit")
    @Audit(businessTitle = BusinessTitle.SERVICE_TYPE, businessAction = BusinessAction.UPDATED, description = "修改服务类型")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZkServiceType zkServiceType)
    {
        zkServiceType.setUpdateBy(getLoginName());
        return toAjax(zkServiceTypeService.updateZkServiceType(zkServiceType));
    }

    /**
     * 删除服务类型
     */
    @RequiresPermissions("system:svtype:remove")
    @Audit(businessTitle = BusinessTitle.SERVICE_TYPE, businessAction = BusinessAction.DELETED, description = "删除服务类型")
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zkServiceTypeService.deleteZkServiceTypeBySvtypeIds(ids));
    }

    /**
     * 服务类型状态修改
     */
    @Audit(businessTitle = BusinessTitle.SERVICE_TYPE, businessAction = BusinessAction.UPDATED, description = "服务类型状态修改")
    @RequiresPermissions("system:svtype:edit")
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(ZkServiceType svtype)
    {
        return toAjax(zkServiceTypeService.changeStatus(svtype));
    }


    @RequiresPermissions("system:svtype:approve")
    @GetMapping("/approve")
    public String approve(ZkServiceType svtype, ModelMap mmap){
        ZkServiceType zkServiceType = zkServiceTypeService.selectZkServiceTypeBySvtypeId(svtype.getSvtypeId());
        mmap.addAttribute("zkServiceType", zkServiceType);
        return prefix + "/approve";
    }

    @RequiresPermissions("system:svtype:approve")
    @Audit(businessTitle = BusinessTitle.SERVICE_TYPE, businessAction = BusinessAction.APPROVED, description = "服务类型审核")
    @PostMapping("/approve")
    @ResponseBody
    public AjaxResult approve(ZkServiceType zkServiceType){
        zkServiceType.setApproveBy(getLoginName());
        zkServiceType.setApproveTime(DateUtils.getNowDate());
        return toAjax(zkServiceTypeService.approve(zkServiceType));
    }

}
